package com.dhcc.redis.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhcc.redis.entity.Student;
import com.dhcc.redis.repository.StudentRepository;
import com.dhcc.redis.service.StudentService;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentRepository studentRepository;

    /**
     * 保存学生信息
     * @param student
     * @return
     */
    @Override
    public Student save(Student student) {
        return studentRepository.save(student);
    }

    /**
     * 根据 Id 查询学生信息
     * @param id
     * @return
     */
    @Override
    public Student findStudentById(Integer id) {
        return studentRepository.findById(id).get();
    }

    /**
     * 删除学生信息
     * @param id
     */
    @Override
    public void delete(Integer id) {
        Student student = this.findStudentById(id);
        studentRepository.delete(student);
    }

    /**
     * 更新学生信息
     * @param student
     */
    @Override
    public void updateStudent(Student student) {
        studentRepository.save(student);
    }

    /**
     * 查询学生信息列表
     * @return
     */
    @Override
    public List<Student> findStudentList() {
        return studentRepository.findAll();
    }

	@Override
	public int saveStudents(List<Student> students) {
		if(null==students)
			return 0;
		return studentRepository.saveAll(students).size();
	}
}
